<?php
/**
 * Created by PhpStorm.
 * User: xuewl
 * Date: 2017/12/23
 * Time: 18:35
 */
namespace app\notification\command;
use think\queue\Job;

class TemplateMessage
{
    /**
     * fire方法是消息队列默认调用的方法
     * @param Job            $job      当前的任务对象
     * @param array|mixed    $data     发布任务时自定义的数据
     */
    public function fire(Job $job,$data) {
        if ($job->attempts() > 3) {
            return $job->delete();
        }
        $model = model('wechat/official_account', 'service');
        $result = $model->template_message->send($data);

        if($result) {
            return $job->delete();
        } else {
            return $job->release(5);
        }
    }
}